function fmtDate(date) {
  let year = date.getFullYear().toString();
  let month = (1 + date.getMonth()).toString();
  let day = date.getDate().toString();
  let hour = date.getHours().toString();
  let min = date.getMinutes().toString();
  let sec = date.getSeconds().toString();

  month = month.length > 1 ? month : '0' + month;
  day = day.length > 1 ? day : '0' + day;
  hour = hour.length > 1 ? hour : '0' + hour;
  min = min.length > 1 ? min : '0' + min;
  sec = sec.length > 1 ? sec : '0' + sec;

  return {
    year,
    month,
    day,
    hour,
    min,
    sec,
  };
}
export function mmdd(date) {
  const { month, day } = fmtDate(date);
  return `${month}/${day}`;
}

export function yyyymmdd(date) {
  const { year, month, day } = fmtDate(date);
  return `${year}${month}${day}`;
}

export function hDate(date) {
  const { year, month, day } = fmtDate(date);
  return `${year}年 ${month}月 ${day}日`;
}

export function addSlash(dateStr) {
  return dateStr.slice(0, 4) + '/' + dateStr.slice(4, 6) + '/' + dateStr.slice(6, 8);
}

export function getWeek(dateStr) {
  let now = new Date(dateStr);
  let onejan = new Date(2021, 0, 1);
  // let year = (now.getFullYear() % 2000) * 100;
  return Math.ceil(((now.getTime() - onejan.getTime()) / 86400000 + onejan.getDay() + 1) / 7);
}

export function fileName() {
  const { year, month, day, hour, min, sec } = fmtDate(new Date());
  return `${year}-${month}-${day} ${hour}:${min}:${sec}.csv`;
}
